def prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    div = int(n ** 0.5) + 1
    for k in range(3, div, 2):
        if n % k == 0:
            return False
    return True


def largest(number):
    st = str(number)
    if not st.isdigit() or len(st) != 4:
        return 0

    m = 0
    n = len(st)
    for i in range(1, n + 1):
        for q in range(n - i + 1):
            substring = st[q:q + i]
            num = int(substring)
            if prime(num) and num > m:
                m = num

    return m

x = int(input())
r = largest(x)
print(r)
